home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Information / CSMP Digest / volume 3 / csmp-digest-v3-116 < prev    next >
Text File  |  1995-12-31  |  79KB  |  2,159 lines

  1. C.S.M.P. Digest             Fri, 13 Oct 95       Volume 3 : Issue 116
  2.  
  3. Today's Topics:
  4.  
  5.         ANSI C++, exceptions, globals, etc, in shared libs?!?
  6.         Creating an Alias
  7.         DNR lib and MacTCP.h
  8.         Getting Volume Icon?
  9.         How do I tell if Time Manager task install was successful?
  10.         How to unlock a volume?
  11.         MakeDataExecutable()?
  12.         Q: Open-Close PPP from Code?
  13.         QuickTime JPEG help
  14.         Storing data in text portion of an application
  15.         Why doesn't the Dialog Manager recognize I moved some controls?
  16.         [Q] Changing Pixmap resolution???
  17.         [Q] Traps not callable from interrupt, why?
  18.  
  19.  
  20.  
  21. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  22. (pottier@clipper.ens.fr).
  23.  
  24. The digest is a collection of article threads from the internet newsgroups
  25. comp.sys.mac.programmer.help, csmp.tools and csmp.misc. It is designed for
  26. people who read news semi-regularly and want an archive of the discussions.
  27. If you don't know what a newsgroup is, you probably don't have access to
  28. it. Ask your systems administrator(s) for details. If you don't have access
  29. to news, you may still be able to post messages to the group by using a
  30. mail server like anon.penet.fi (mail help@anon.penet.fi for more
  31. information).
  32.  
  33. Each issue of the digest contains one or more sets of articles (called
  34. threads), with each set corresponding to a 'discussion' of a particular
  35. subject.  The articles are not edited; all articles included in this digest
  36. are in their original posted form (as received by our news server at
  37. nef.ens.fr).  Article threads are not added to the digest until the last
  38. article added to the thread is at least two weeks old (this is to ensure that
  39. the thread is dead before adding it to the digest).  Article threads that
  40. consist of only one message are generally not included in the digest.
  41.  
  42. The digest is officially distributed by two means, by email and ftp.
  43.  
  44. If you want to receive the digest by mail, send email to listserv@ens.fr
  45. with no subject and one of the following commands as body:
  46.     help                                Sends you a summary of commands
  47.     subscribe csmp-digest Your Name     Adds you to the mailing list
  48.     signoff csmp-digest                 Removes you from the list
  49. Once you have subscribed, you will automatically receive each new
  50. issue as it is created.
  51.  
  52. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  53. Questions related to the ftp site should be directed to
  54. scott.silver@dartmouth.edu.
  55.  
  56. -------------------------------------------------------
  57.  
  58. >From jessholl@netcom.com (Jess Holle)
  59. Subject: ANSI C++, exceptions, globals, etc, in shared libs?!?
  60. Date: Sun, 8 Oct 1995 03:48:13 GMT
  61. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  62.  
  63. I have several applications which use one common class framework.  In CW 6
  64. I made another version of the C runtime library which seemed to work fine
  65. from shared libraries and support the use of the ANSI C library from both
  66. the shared library and my applications.
  67.  
  68. In CW 7, I made another version of the C runtime library in _exactly_ the
  69. same way, rebuilt all precompiled headers and projects, and then got
  70. _lots_ of link errors.  This was not too much of a surprise since I made
  71. one crucial change: I turned direct destruction off and turned C++
  72. exceptions on.  I did this because the release notes state that this is
  73. necessary if you use C++ iostreams.  Also, I wish to use exceptions in the
  74. not too distant future and wanted to make sure that I could when I wanted
  75. to.
  76.  
  77. I have seen lengthy posts from John McEnernery and other Metrowerks people
  78. on how to modify the standard library projects to allow them to work in a
  79. shared library environment.  I thank them for their efforts.  There are
  80. two problems with this, however:
  81.  
  82.   1)  I have not seen a post yet which gives step by step instructions to
  83.       create a single "standard" project or set of projects which allows ANSI
  84.       C and C++ libraries to be used from any PowerPC shared library or
  85.       application, handling exceptions, exit(), abort(), setjmp(), longjmp(),
  86.       Quickdraw globals, SIOUX, etc.  Basically I want to know that all these
  87.       issues are handled so I can have _some_ faith in the runtime mechanisms
  88.       while using shared libraries.
  89.  
  90.   2)  As illustrated by my problems when moving from CW6 to CW7, shared
  91.       library support is somewhat shaky unless shared-library "ready" versions
  92.       of the ANSI and runtime libraries are provided either in the release or
  93.       on the web site.  Let me explain.  Assume that I make all the changes
  94.       necessary to the ANSI and runtime libraries in order to achieve the
  95.       perfect shared-library ready support libraries.  Next CW8 comes out and
  96.       I have to revamp these support libraries, as does everyone else who has
  97.       done such tinkering.  Same goes for CW version N.  This would also seem
  98.       to create a technical support nightmare (or is no one using shared
  99.       libraries all that much?)
  100.  
  101. Don't get me wrong.  Metrowerks is doing a fantastic job.  Code Warrior is
  102. a joy to use overall.  It seems, however, that using the ANSI and runtime
  103. support libraries with shared libraries has been unnecessarily left as a
  104. black art.
  105.  
  106. If anyone has successfully created versions of the runtime library that
  107. allow the use of:
  108.   - Quickdraw globals,
  109.   - exceptions,
  110.   - abort(), exit(), setjmp(), etc,
  111.   - ANSI C and C++ libraries, and
  112.   - SIOUX
  113. from within shared libraries with no strange restrictions, I would love to
  114. hear from them.
  115.  
  116. It would be ideal if several wise people could whip together the projects
  117. necessary and get them placed on Metrowerks web site and/or release CDs. 
  118. It would even better if this was done by Metrowerks so these projects had
  119. full technical support, bug fixing, and maintenance from release to
  120. release.
  121.  
  122. I'm sorry to have run on so long.  It just seems that shared libraries are
  123. becoming an important part of the Mac runtime environment, especially when
  124. using one or more common frameworks.  It therefore seems that solid,
  125. standard runtime support for this environment should be part of the
  126. development package, not something that must be hacked out with each
  127. release of the runtime libraries.
  128.  
  129. Sincerely,
  130. Jess Holle
  131.  
  132. - -------------------------------------------------------------------
  133. Jess Holle    /                                   jessholl@netcom.com
  134. Norwood, MA  /  ftp://ftp.netcom.com/pub/je/jessholl/j_and_w_www.html
  135.  
  136. +++++++++++++++++++++++++++
  137.  
  138. >From ari@shore.net (Ari Halberstadt)
  139. Date: Wed, 11 Oct 1995 16:19:10 -0400
  140. Organization: North Shore Access/Eco Software, Inc; (info@shore.net)
  141.  
  142. In article <jessholl-0710952350220001@10.0.2.15>, jessholl@netcom.com
  143. (Jess Holle) wrote:
  144. >...
  145. >  1)  I have not seen a post yet which gives step by step instructions to
  146. >      create a single "standard" project or set of projects which allows ANSI
  147. >      C and C++ libraries to be used from any PowerPC shared library or
  148. >      application, handling exceptions, exit(), abort(), setjmp(), longjmp(),
  149. >      Quickdraw globals, SIOUX, etc.  Basically I want to know that all these
  150. >      issues are handled so I can have _some_ faith in the runtime mechanisms
  151. >      while using shared libraries.
  152. >...
  153. >If anyone has successfully created versions of the runtime library that
  154. >allow the use of:
  155. >  - Quickdraw globals,
  156. >  - exceptions,
  157. >  - abort(), exit(), setjmp(), etc,
  158. >  - ANSI C and C++ libraries, and
  159. >  - SIOUX
  160. >from within shared libraries with no strange restrictions, I would love to
  161. >hear from them.
  162. >...
  163.  
  164. I do not have a complete solution to your request. However, I can help you
  165. with supporting setjmp, longjmp, and QuickDraw global variables in plain
  166. ANSI C code (I have not done this with C++ code). My shared library does
  167. not use the full ANSI library. To use setjmp and longjmp, add the files
  168. setjmp.o and runtime.o from the runtime folder to your library's project.
  169. Use a .exp file to specify the symbols to export. Make sure you do not
  170. export longjmp from your library. You will also need to declare a dummy
  171. destructor chain:
  172.  
  173. void *__local_destructor_chain;
  174.  
  175. When you call setjmp, make sure that it is called directly in the code
  176. fragment to which you want the call to apply. This ensures that the
  177. correct TOC register is saved. Similarly, when you call longjmp, you must
  178. ensure that the longjmp corresponding to the setjmp you had called is
  179. used. For instance, if you call setjmp from fragment a, then you must also
  180. call the longjmp compiled with fragment a, even if you call the longjmp
  181. while executing code in fragment b. The solution I found was to store a
  182. pointer to the longjmp function at the time setjmp is called. Something
  183. like the following,
  184.  
  185. struct JumpEnvironment {
  186.   jmp_buf jmpbuf;
  187.   LongjmpPtr jump;
  188. };
  189.  
  190. JumpEnvironment env;
  191. env->jump = longjmp;
  192. if (setjmp(env->jmpbuf) == 0) ...
  193.  
  194. ...
  195. env->jump(env->jmpbuf, 1);
  196. ...
  197.  
  198. This precaution guards against the possibility that the jump buffer's
  199. format could be different in the two shared libraries. This actually
  200. happened to me when I used setjmp.o in one library but used a different
  201. setjmp in a second library (via the ANSI library).
  202.  
  203. Last week I posted one method of accessing QuickDraw global variables from
  204. a shared library. Here is the post again (including a few slight errors).
  205. Also enclosed is a reply describing an alternative method.
  206.  
  207. Path: shore!slip-5-3.shore.net!user
  208. From: ari@shore.net (Ari Halberstadt)
  209. Newsgroups: comp.sys.mac.programmer.codewarrior,alt.sources.mac
  210. Subject: My recipe for QD globals in shared lib (was Re: shared libraries
  211. and quickdraw globals)
  212. Date: Mon, 25 Sep 1995 01:10:41 -0400
  213. Organization: North Shore Access/Eco Software, Inc; (info@shore.net)
  214. Lines: 245
  215. Message-ID: <ari-2509950110410001@slip-5-3.shore.net>
  216. References: <4357i3$ags@colossus.holonet.net> <coopmanDF9zB6.Jo5@netcom.com>
  217. Reply-To: comp.sys.mac.programmer.codewarrior
  218. NNTP-Posting-Host: slip-5-3.shore.net
  219. Xref: shore comp.sys.mac.programmer.codewarrior:25526 alt.sources.mac:2507
  220.  
  221. Accessing the QuickDraw global variables from a fragment is not as simple as
  222. "Inside Macintosh:PowerPC System Software" [IM:PPCSS] might lead you to believe.
  223. IM:PPCSS, p1-57 to 1-63 says that a limited A5 world is created for
  224. applications.
  225. This limited A5 world supposedly provides access to the QuickDraw global
  226. variables using the technique documented in "Inside Macintosh: Memory", p4-18 to
  227. p4-19. It turns out, however, that Metrowerks CodeWarior v6 does not
  228. configure the A5 world in a manner allowing this technique to work*. For
  229. PPC-native code, you need to use the Code Fragment Manager to locate the
  230. QuickDraw
  231. global variables. This document provides a recipe, of sorts, for doing this.
  232.  
  233. Disclaimer: The code and steps provided in this document are based on my own
  234. code. However, these specific code examples have not been tested. Use at
  235. your own
  236. risk.
  237.  
  238. * I may just be confused in my reading of IM:PPCSS or my analysis of the
  239. A5 world
  240. generated by Codewarrior. At any rate, I could not get the technique
  241. described in
  242. IM:Memory to work in a native PowerPC application, but I could get it to work in
  243. an emulated 68K application.
  244.  
  245. Modifications to your shared library
  246. ====================================
  247.  
  248. The following modifications allow your shared library to resolve, at
  249. runtime, the
  250. address of the QuickDraw global variables.
  251.  
  252. - Define a couple of functions to locate a symbol.
  253.  
  254. /* CurrentProcessConnectionID returns the connection ID for the fragment located
  255.    in the current process's application file. This is based on "InitResource.c",
  256.    by Mark Anderson of Metrowerks. */
  257. OSErr CurrentProcessConnectionID(CFragConnectionID *connectionID)
  258. {
  259.    Ptr mainAddress;
  260.    Str255 errorMessage;
  261.    Str255 processName;
  262.    FSSpec processSpec;
  263.    ProcessSerialNumber psn;
  264.    ProcessInfoRec processInfo;
  265.    OSErr err;
  266.    
  267.    processInfo.processInfoLength = sizeof(ProcessInfoRec);
  268.    processInfo.processName = processName;
  269.    processInfo.processAppSpec = &processSpec;
  270.    psn.highLongOfPSN = 0;
  271.    psn.lowLongOfPSN = kCurrentProcess;
  272.    err = GetProcessInformation(&psn, &processInfo);
  273.    if (! err) {
  274.       err = GetDiskFragment(&processSpec, 0L, 0L, processName, kFindCFrag,
  275.             connectionID, &mainAddress, errorMessage);
  276.    }
  277.    return(err);
  278. }
  279.  
  280. /* FindSymbolInSelfOrCaller searches for a symbol first in the
  281.    current fragment and then in the fragment for the current
  282.    process. */
  283. OSErr FindSymbolInSelfOrCaller(ConstStr255Param symbolName,
  284.    Ptr *symbolAddress,
  285.    SymClass *symbolClass)
  286. {
  287.    CFragConnectionID currentID;
  288.    OSErr err;
  289.       
  290.    err = FindSymbol(gInitBlock.connectionID, symbolName, symbolAddress,
  291. symbolClass);
  292.    if (err == fragSymbolNotFound) {
  293.       err = CurrentProcessConnectionID(¤tID);
  294.       if (! err)
  295.          err = FindSymbol(currentID, symbolName, symbolAddress, symbolClass);
  296.    }
  297.    return(err);
  298. }
  299.  
  300. - Define a start symbol for your code fragment. Something like:
  301.  
  302. /* Copy of initialization block passed to wsCFInitialize. */
  303. CFragInitBlock gInitBlock;
  304.  
  305. /* The fragment's initialization function. */
  306. OSErr Initialize(CFragInitBlockPtr initBlock)
  307. {
  308.    gInitBlock = *initBlock;
  309.    return(noErr);
  310. }
  311.  
  312. This just saves a copy of the initialization block passed to the fragment. We
  313. make a copy of the initialization block because "Inside Macintosh: PowerPC
  314. System
  315. Software" does not indicate the scope of the pointer to the initialization
  316. block.
  317. It appears that the initialization block remains valid as long as the fragment
  318. remains loaded, but this little fact is not documented. This means, for
  319. instance,
  320. that we cannot really be certain that the fields of the CFragHFSLocator
  321. are valid
  322. after the initialization function returns. We are only interested, however, in
  323. the connection and context IDs, which are just long integers, so a copy of the
  324. initialization block will work ok.
  325.  
  326. Note: instead of using the Process Manager to locate the file containing
  327. the fragment, we could use the fragLocator field of the CFragInitBlock
  328. record.
  329.  
  330. - Set the initialization function of your fragment. If you're using Metrowerks
  331. CodeWarrior, then enter the initialization function's name in the
  332. "Initialization" entry point field in the "Linker" pane of the preferences
  333. dialog
  334. for your fragment's project file.
  335.  
  336. - Add the following declaration in some common header file:
  337.  
  338.    extern QDGlobals *gQDGlobals;
  339.  
  340. Also, add the following definition in some source file:
  341.  
  342.    QDGlobals *gQDGlobals;
  343.    
  344. - Do a global search and replace and change all references to "qd." to
  345. "gQDGlobals->", and then change all references to "qd" (without the member
  346. access operator) to "gQDGlobals".
  347.  
  348. - Add the following lines before you first use the QuickDraw global variables:
  349.  
  350.    #if GENERATINGCFM
  351.       CFragSymbolClass symbolClass;
  352.       OSErr err;
  353.       
  354.       err = FindSymbolInSelfOrCaller((StringPtr) "\pqd", (Ptr *)
  355. &gQDGlobals, &symbolClass);
  356.       if (err != noErr)
  357.          /* handle the error, probably just ExitToShell */;
  358.    #else
  359.       gQDGlobals = (QDGlobals *) ((*(long *) SetCurrentA5()) -
  360. sizeof(QDGlobals) + sizeof(GrafPtr));
  361.    #endif
  362.    
  363. - Rebuild your fragment.
  364.  
  365. Modifications to your application
  366. =================================
  367.  
  368. The following modifications export the QuickDraw global variables from your
  369. application, so that your shared library can access them.
  370.  
  371. - Generate a ".exp" file for the calling application. If you're using Metrowerks
  372. CodeWarrior, then turn on "use “.exp” file" from the "Export Symbols" popup menu
  373. in the "PEF" panel of the preferences dialog for your application's project and
  374. remake the project. You may get a bunch of errors about undefined symbols, e.g.,
  375. SIOUX and CodeWarrior runtime stuff; you can ignore these errors.
  376.  
  377. - Open the ".exp" file. The ".exp" file will initially contain all the global
  378. symbols in your application. Remove everything but the symbols you want to
  379. export, i.e., "qd". Remake the project again.
  380.  
  381. - Run. Hopefully, everything will work.
  382.  
  383. Accessing Functions
  384. ===================
  385.  
  386. This is an example of how you might use the above technique to locate functions.
  387. I use code similar to the following examples to avoid having to include the ANSI
  388. library in my shared library yet still be able to allocate memory (you could use
  389. any application-defined memory allocation routines by changing the names of the
  390. functions). Remember to add the names of any symbols you want to access in your
  391. shared library to your application's ".exp" file.
  392.  
  393. #if GENERATINGCFM
  394.    #define FindSymbolNative(addr, name)
  395. FindSymbolAddressInSelfOrCaller((StringPtr) name)
  396. #else
  397.    #define FindSymbolNative(addr, name) (addr)
  398. #endif
  399.  
  400. typedef void *(*MallocProcPtr)(size_t n);
  401. typedef void (*FreeProcPtr)(void *p);
  402.  
  403. /* Returns the address of the malloc function. */
  404. static MallocProcPtr FindMalloc(void)
  405. {
  406.    static MallocProcPtr mallocProc;
  407.  
  408.    if (! mallocProc)
  409.       mallocProc = FindSymbolNative(malloc, "\pmalloc");
  410.    return(mallocProc);
  411. }
  412.  
  413. /* Returns the address of the free function. */
  414. static FreeProcPtr FindFree(void)
  415. {
  416.    static FreeProcPtr freeProc;
  417.  
  418.    if (! freeProc)
  419.       freeProc = FindSymbolNative(free, "\pfree");
  420.    return(freeProc);
  421. }
  422.  
  423. Notice that I use exceptions for error handling, so
  424. FindSymbolAddressInSelfOrCaller
  425. looks more like
  426.  
  427. void *FindSymbolAddressInSelfOrCaller(Str255 symbolName)
  428. {
  429.    Ptr symbolAddress;
  430.    CFragSymbolClass symbolClass;
  431.    OSErr err;
  432.       
  433.    err = FindSymbol(gInitBlock.connectionID, symbolName, &symbolAddress,
  434. &symbolClass);
  435.    if (err == fragSymbolNotFound) 
  436.       err = FindSymbol(CurrentProcessConnectionID(), symbolName,
  437. &symbolAddress, &symbolClass);
  438.    ThrowIfOSErr(err);
  439.   assert(symbolAddress != NULL);
  440.    return(symbolAddress);
  441. }
  442.  
  443. Unanswered Questions
  444. ====================
  445.  
  446. 1. What are the contextID and closure ID fields in the CFragInitBlock
  447. record? Could
  448. these fields be used rather than locating the current process' file?
  449.  
  450. 2. Is the pointer (and all fields) of the CFragInitBlock passed to the
  451. initialization
  452. routine guaranteed to remain valid for the duration of the connection to the
  453. initialized fragment?
  454.  
  455. CodeWarrior 7 Bonuses
  456. =====================
  457.  
  458. Debugging PPC shared libraries WORKS! Yippy! And the MetroNub doohicky
  459. makes setting
  460. conditional breakpoints feasible. I still get the stupid -108 error from
  461. the Scrap
  462. Manager, though. Also, I haven't quite gotten my 68K shared library to link.
  463.  
  464. -- Ari Halberstadt (ari@shore.net, ari@world.std.com)
  465. For latest versions of some of my Macintosh software try
  466. <ftp://ftp.shore.net/members/ari>.
  467.  
  468. Path:
  469. shore!uunet!in2.uu.net!svc.portal.com!news1.best.com!shellx.best.com!ckt.vip.best.com!user
  470. From: ckt@best.com (Chris Thomas)
  471. Newsgroups: comp.sys.mac.programmer.codewarrior,alt.sources.mac
  472. Subject: Re: My recipe for QD globals in shared lib (was Re: shared
  473. libraries and quickdraw globals)
  474. Date: Fri, 29 Sep 1995 01:40:19 -0800
  475. Organization: Echo Software
  476. Lines: 20
  477. Message-ID: <ckt-2909950140190001@ckt.vip.best.com>
  478. References: <4357i3$ags@colossus.holonet.net>
  479. <coopmanDF9zB6.Jo5@netcom.com> <ari-2509950110410001@slip-5-3.shore.net>
  480. NNTP-Posting-Host: ckt.vip.best.com
  481. X-Newsreader: Yet Another NewsWatcher 2.0b30
  482. Xref: shore comp.sys.mac.programmer.codewarrior:26014 alt.sources.mac:2537
  483.  
  484. If you control the application as well as the sharedlib, this
  485. can be vastly simplified.  Declare "QDGlobals qd" explicitly in
  486. your app.  Make sure the file with this declaration comes before
  487. the MWCRuntime lib.  Export "qd" using the .exp file.  When you
  488. link, you'll get a warning that the "qd" declaration in Startup.c
  489. was ignored, which is what you want (alternately, you can comment
  490. out the "QDGlobals qd" declaration in Startup.c and rebuild
  491. MWCRuntime.)
  492.  
  493. In the sharedlib, either include the application as a shared
  494. library or use a dummy shared library with the "qd" symbol
  495. exported.  Again, be sure this library is positioned before
  496. MWCRuntime in the project file.
  497.  
  498. When the app connects to your code fragment, your app is still in
  499. the loader's search path and connects qd up to the application's
  500. qd automatically.
  501.  
  502. -- 
  503. Chris Thomas, ckt@best.com
  504.  
  505. -- Ari Halberstadt (ari@shore.net, ari@world.std.com)
  506. For latest versions of some of my Macintosh software try <ftp://ftp.shore.net/members/ari>.
  507.  
  508. ---------------------------
  509.  
  510. >From strauss@ap.org (Fred Strauss)
  511. Subject: Creating an Alias
  512. Date: Wed, 27 Sep 1995 11:56:03 -0400
  513. Organization: The Associated Press
  514.  
  515. Is there a way to create an alias of a file via Apple Events sent to the
  516. Finder? What I'm trying to do from within an installer is create an alias
  517. of an application in the startup items folder.
  518.  
  519. I see there is a script that came with System 7.5 called 'Add Alias to
  520. Apple Menu' and I'm wondering if I could somehow call a modified version
  521. of this script from my installer or mimic its functionality via apple
  522. events to the finder?
  523.  
  524. Thanks,
  525. Fred
  526.  
  527. +++++++++++++++++++++++++++
  528.  
  529. >From jumplong@aol.com (Jump Long)
  530. Date: 29 Sep 1995 02:50:05 -0400
  531. Organization: America Online, Inc. (1-800-827-6364)
  532.  
  533. Fred Strauss wrote:
  534. >Is there a way to create an alias of a file via Apple Events
  535. >sent to the Finder? What I'm trying to do from within an
  536. >installer is create an alias of an application in the startup
  537. >items folder.
  538.  
  539. Fred, you should start with the article "Scripting the Finder From Your
  540. Application" by Greg Anderson in develop managzine, issue 20. You can find
  541. that on Apple's Developer CD or on the web at:
  542.  
  543. http://www.info.apple.com/dev/develop/issue20/20anderson.html
  544.  
  545. The code for Greg's article is at:
  546.  
  547. ftp://ftp.info.apple.com/Apple.Support.Area/Developer_Services/Periodicals
  548. /develop/develop20/develop_20_code/Scripting_the_Finder.sit.hqx
  549.  
  550. Hope that give you a good start.
  551.  
  552. - Jim Luther
  553.  
  554. ---------------------------
  555.  
  556. >From Martin.Friedrich@arbi.informatik.uni-oldenburg.de (Martin Friedrich)
  557. Subject: DNR lib and MacTCP.h
  558. Date: Thu, 21 Sep 1995 09:58:02 GMT
  559. Organization: University of Oldenburg, Germany
  560.  
  561. Hi, all!
  562.  
  563. I've noticed that the declaration of the DNR routines in MacTCP.h from the
  564. Universal Headers don't match those in DNR.c. In MacTCP.h they're all 
  565. pascal OSErr, whereas in DNR.c they are OSErr declared. Is there a newer
  566. (or say more uptodate) DNR-library I missed, or is this a bug in the
  567. Universal Headers?
  568.  
  569. Thanks in advance,
  570.         Martin Friedrich
  571.  
  572.  
  573. +++++++++++++++++++++++++++
  574.  
  575. >From scouten@uiuc.edu (Eric Scouten)
  576. Date: Wed, 27 Sep 1995 10:21:04 -0500
  577. Organization: Huh? What's that?
  578.  
  579. In article <1995Sep21.100351.13084@arbi.Informatik.Uni-Oldenburg.DE>,
  580. Martin.Friedrich@arbi.informatik.uni-oldenburg.de (Martin Friedrich)
  581. wrote:
  582.  
  583. > I've noticed that the declaration of the DNR routines in MacTCP.h from the
  584. > Universal Headers don't match those in DNR.c. In MacTCP.h they're all 
  585. > pascal OSErr, whereas in DNR.c they are OSErr declared. Is there a newer
  586. > (or say more uptodate) DNR-library I missed, or is this a bug in the
  587. > Universal Headers?
  588.  
  589. The latest that I've seen has the declarations in <AddressXlation.h> and
  590. the source in <dnr.c>. They are consistently declared as C functions (i.e.
  591. no pascal keyword).
  592.  
  593. (This is the version shipping on CW/7 which is from Universal Headers 2.1b1.)
  594.  
  595. -es
  596.  
  597. __________________________________________________________________________
  598. Eric Scouten                                       Constructor Constructor
  599. scouten@metrowerks.com                                     Metrowerks, Inc.
  600.  
  601. If you still can't figure out how to get on the list, you're probably a
  602. "Family Circus" fan anyway and not destined to mingle with the new ruling
  603. class except maybe as domestic help.  
  604.    -Scott Adams
  605.  
  606. ---------------------------
  607.  
  608. >From rajadhyaksha.2@osu.edu (Ram Rajadhyaksha)
  609. Subject: Getting Volume Icon?
  610. Date: Sat, 23 Sep 1995 19:42:33 -0400
  611. Organization: The Ohio State University
  612.  
  613. I want to do a cool volume selection dialog box with the icon of the
  614. volume next to the pop-up menu. The question is, where the hell is the
  615. icon data stored? I'm guessing that it's either an "Icon" file in the root
  616. directory or something that is set on the driver level.
  617.  
  618. Any help is greatly appreciated...
  619.  
  620. -Ram
  621.  
  622. +++++++++++++++++++++++++++
  623.  
  624. >From jumplong@aol.com (Jump Long)
  625. Date: 25 Sep 1995 02:52:01 -0400
  626. Organization: America Online, Inc. (1-800-827-6364)
  627.  
  628. Ram Rajadhyaksha writes:
  629.  
  630. >I want to do a cool volume selection dialog box with the icon of
  631. >the volume next to the pop-up menu. The question is, where the
  632. >hell is the icon data stored? I'm guessing that it's either an
  633. >"Icon" file in the root directory or something that is set on
  634. >the driver level.
  635.  
  636. The standard icon for a drive can be obtained with PBControl and csCode
  637. 22. If you want the icon the Finder is showing, just ask the Finder for it
  638. (assuming you're running the scriptable Finder). If you can't get it from
  639. the Finder, then you'll need to check the root directory to see if it has
  640. the hasCustomIcon Finder flag bit set and if so, read the ICON resource
  641. out of the Icon(c/r) file in the root directory.
  642.  
  643. - Jim Luther
  644.  
  645. ---------------------------
  646.  
  647. >From reed@medicine.wustl.edu (Thomas Reed)
  648. Subject: How do I tell if Time Manager task install was successful?
  649. Date: Wed, 27 Sep 1995 08:48:17 -0500
  650. Organization: Washington University
  651.  
  652. One of my programs installs a Time Manager task that runs once every five
  653. seconds.  Unfortunately, my program does things sometimes that make me
  654. think that the task wasn't successfully installed.  Since InsXTime and
  655. PrimeTime don't return any kind of error, I'm not sure how to verify
  656. this.  Anyone else know?
  657.  
  658. Thanks in advance!
  659.  
  660. -Thomas
  661.  
  662. =====================================================
  663. Thomas Reed                     Washington University
  664. reed@visar.wustl.edu               Medical School
  665. reed@medicine.wustl.edu            Saint Louis, MO
  666. http://medinfo.wustl.edu/~reed
  667. - ---------------------------------------------------
  668. Clothes make the man.  Naked people have little or no
  669. influence on society.  -- Mark Twain
  670. =====================================================
  671.  
  672. Opinions posted are not the opinions of Wash. U.
  673.  
  674. +++++++++++++++++++++++++++
  675.  
  676. >From ari@shore.net (Ari Halberstadt)
  677. Date: Thu, 28 Sep 1995 01:21:43 -0400
  678. Organization: North Shore Access/Eco Software, Inc; (info@shore.net)
  679.  
  680. In article <reed-2709950848170001@thomasmac.wustl.edu>,
  681. reed@medicine.wustl.edu (Thomas Reed) wrote:
  682.  
  683. >One of my programs installs a Time Manager task that runs once every five
  684. >seconds.  Unfortunately, my program does things sometimes that make me
  685. >think that the task wasn't successfully installed.  Since InsXTime and
  686. >PrimeTime don't return any kind of error, I'm not sure how to verify
  687. >this.  Anyone else know?
  688.  
  689. Try looking in the queue header (it's some low-mem global, I think), and
  690. walk it in MacsBug till you hit your task. Or use a high-level debugger by
  691. grabbing the address into a queue variable with the right structure so,
  692. say, Metrowerks debugger can expand each next pointer. Give it a big time
  693. value, so that it isn't removed and added while you're looking at the
  694. queue, which, admittedly, is likely to change from moment to moment. Maybe
  695. you can do a quick search of the queue with a loop, something like
  696.  
  697.  for (task = GetFirstTask(); task != NULL && task != myTask; task =
  698. GetNextTask(task))
  699.    ;
  700.  if (task == NULL)
  701.    DebugStr("\p not there");
  702.  
  703. You could also change your task to increment a global variable. Set the
  704. task to execute every second. Have some display routine (not called from
  705. the task) print the variable (or look at it in the debugger). If it
  706. doesn't increment every second, the task is hozed.
  707.  
  708. Also, remember to put in an ExitToShell patch to remove your task, this
  709. killed almost 2 days of my time recently (1 day to figure out how stupid I
  710. was to not remove the task, 1 day to figure out the patch). Here's my
  711. patch:
  712.  
  713. /* Called on termination to do any final cleanup,
  714.    which, if it were not done, would cause a crash. */
  715. static void CleanupFinal(void)
  716. {
  717.    wsClockRemoveAll();
  718. }
  719.  
  720. /* Patch for ExitToShell. This patch is used to remove things that must be
  721.    removed when the application terminates to prevent the system from
  722.    crashing. This patch is really just a precaution for situations where
  723.    wsAppExit does not get called. */
  724.  
  725. static UniversalProcPtr gExitToShell;
  726.  
  727. static pascal void PatchedExitToShell(void)
  728. {
  729.    long oldA5;
  730.  
  731.    oldA5 = SetCurrentA5();
  732.    SetToolTrapAddress(gExitToShell, _ExitToShell);
  733.    CleanupFinal();
  734.    (void) SetA5(oldA5);
  735.    ExitToShell();
  736. }
  737.  
  738. static void PatchExitToShell(void)
  739. {
  740.    if (wsMacVersion() < wskSystemVersion8) {
  741.       gExitToShell = GetToolTrapAddress(_ExitToShell);
  742.       SetToolTrapAddress(NewRoutineDescriptor((ProcPtr) PatchedExitToShell,
  743.             kPascalStackBased, GetCurrentArchitecture()), _ExitToShell);
  744.    }
  745. }
  746.  
  747. Copland is supposed to do the proper cleanup, so the patch isn't installed
  748. under system 8.
  749.  
  750. -- Ari Halberstadt (ari@shore.net, ari@world.std.com)
  751. For latest versions of some of my Macintosh software try <ftp://ftp.shore.net/members/ari>.
  752.  
  753. +++++++++++++++++++++++++++
  754.  
  755. >From scouten@uiuc.edu (Eric Scouten)
  756. Date: Thu, 28 Sep 1995 13:24:49 -0500
  757. Organization: Huh? What's that?
  758.  
  759. In article <reed-2709950848170001@thomasmac.wustl.edu>,
  760. reed@medicine.wustl.edu (Thomas Reed) wrote:
  761.  
  762. > One of my programs installs a Time Manager task that runs once every five
  763. > seconds.  Unfortunately, my program does things sometimes that make me
  764. > think that the task wasn't successfully installed.  Since InsXTime and
  765. > PrimeTime don't return any kind of error, I'm not sure how to verify
  766. > this.  Anyone else know?
  767.  
  768. InsXTime eventually calls Enqueue which doesn't fail unless you've managed
  769. to form a bad queue -- in which case it fails so spectacularly that
  770. there's really no question it failed. (Suffice it to say that return codes
  771. would not be an issue.) If you can read 68K assembly, drop into MacsBug
  772. and type "il Enqueue". You'll see what I mean.
  773.  
  774. Possible thoughts:
  775.  
  776. [1] You've passed a really wacked-out time interval to PrimeTime.
  777. [2] You haven't restored your globals properly. On 68K (non-CFM), you need
  778.     to manually save and restore the A5 register.
  779.  
  780. If one of these doesn't explain it, perhaps you could post with more
  781. details of what's (not?) happening. I'd also be willing to look at a short
  782. snippet to see if there's anything obvious to me.
  783.  
  784. -es
  785.  
  786. __________________________________________________________________________
  787. Eric Scouten                                       Constructor Constructor
  788. scouten@metrowerks.com                                     Metrowerks, Inc.
  789.  
  790. This is the biggest thing since new coke.
  791.    - R. Schnieder (New York Times) trying out Windows 95
  792.  
  793. ---------------------------
  794.  
  795. >From Rocco Moliterno <rocco@mbox.vol.it>
  796. Subject: How to unlock a volume?
  797. Date: 24 Sep 1995 14:50:32 GMT
  798. Organization: Italia Online
  799.  
  800. The right way to lock/unlock a volume, by software flag, should be:
  801.  
  802.                 err = PBHGetVInfoSync(&pb);
  803.                 pb.ioVAtrb |= 0x8000; //to lock
  804.                 or
  805.                         pb.ioVAtrb &=0x7FFF; //to unlock
  806.                 err = PBSetVInfoSync(&pb);
  807.  
  808. No problems to lock, but is impracticable to unlock a volume (already 
  809. locked by software) because the volume IS LOCKED, as a result can't 
  810. write on it.
  811.  
  812. What is the TRUE right way?
  813.  
  814. Please, send answer (even) to : rocco@mbox.vol.it, because I can't read 
  815. this newsgroup even.
  816.  
  817. Thanks.
  818.  
  819. Rocco
  820.  
  821. Rocco Moliterno
  822. rocco@mbox.vol.it
  823.  
  824.  
  825.  
  826. +++++++++++++++++++++++++++
  827.  
  828. >From chris-b@cs.auckland.ac.nz (chris-b)
  829. Date: Wed, 27 Sep 1995 12:32:26 +1200
  830. Organization: HyperMedia Unit, Comp Sci, Auckland University
  831.  
  832. In article <443r7o$9d5@mikasa.iol.it>, Rocco Moliterno <rocco@mbox.vol.it>
  833. wrote:
  834.  
  835. >The right way to lock/unlock a volume, by software flag, should be:
  836. >
  837. >                err = PBHGetVInfoSync(&pb);
  838. >                pb.ioVAtrb |= 0x8000; //to lock
  839. >                or
  840. >                        pb.ioVAtrb &=0x7FFF; //to unlock
  841. >                err = PBSetVInfoSync(&pb);
  842. >
  843. >No problems to lock, but is impracticable to unlock a volume (already 
  844. >locked by software) because the volume IS LOCKED, as a result can't 
  845. >write on it.
  846.  
  847. I haven't tried it, but I think you'd have to walk the VCB queue and clear
  848. (or is it set??) the bit(s) "manually".
  849.  
  850. Use the _GetVCBQHdr trap to get the head of the VCB queue.
  851.  
  852. ChrisB
  853. - ---------------------------------------------------------------------
  854. NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
  855. Internet: chris-b@cs.auckland.ac.nz
  856. Phone:    +64 9 373-7599 x6194
  857. Fax:      +64 9 373-7453                         Async, therefore I am.
  858. - ---------------------------------------------------------------------
  859.  
  860. ---------------------------
  861.  
  862. >From Karl_A._Bunker@maceast.com (Karl A. Bunker)
  863. Subject: MakeDataExecutable()?
  864. Date: Fri, 22 Sep 95 11:13:49 EDT
  865. Organization: MacEAST
  866.  
  867. In a discussion of self-modifying code, I've seen a reference to a toolbox
  868. call "MakeDataExecutable". I can't find any documentation on this call in IM:
  869. Memory, Think Ref., or in Apple's Headers. Anyone know where I can get some
  870. info on it?
  871.  
  872. Karl Bunker
  873.  
  874.  
  875. --
  876.  
  877. - ---------------------
  878. via MacEAST, Boston
  879. http://www.maceast.com/
  880.  
  881. +++++++++++++++++++++++++++
  882.  
  883. >From grobbins@znet.com (Grobbins)
  884. Date: Mon, 25 Sep 1995 21:38:08 -0700
  885. Organization: Skunkworks
  886.  
  887. In article <1465651.ensmtp@maceast.com>, Karl_A._Bunker@maceast.com (Karl
  888. A. Bunker) wrote:
  889. >In a discussion of self-modifying code, I've seen a reference to a toolbox
  890. >call "MakeDataExecutable". I can't find any documentation on this call in IM:
  891. >Memory, Think Ref., or in Apple's Headers. Anyone know where I can get some
  892. >info on it?
  893.  
  894. It's in the latest Universal Headers.  Checking the headers included with
  895. CodeWarrior 7, the routine is declared in OSUtils.p as
  896.  
  897. {$IFC GENERATINGPOWERPC }
  898. PROCEDURE MakeDataExecutable(baseAddress: UNIV Ptr; length: LONGINT);
  899. {$ENDC}
  900.  
  901. and in OSUtils.h as
  902.  
  903. #if GENERATINGPOWERPC
  904. extern pascal void MakeDataExecutable(void *baseAddress, unsigned long length);
  905. #endif
  906.  
  907. MakeDataExecutable was first documented in issue 18 of develop magazine;
  908. check out the sidebar on caching on page 53 of that issue.  Note that the
  909. sidebar suggests FlushInstructionCache as a 68K counterpart to
  910. MakeDataExecutable, but these days where possible it is preferable to call
  911. FlushCodeCacheRange to flush 68K code, as specifying the range can avoid
  912. needless speed hits when running under the DR Emulator. 
  913. FlushCodeCacheRange is documented in tech note HW 6 - "Cache as Cache
  914. Can".
  915.  
  916.  
  917. Grobbins                                         grobbins@znet.com
  918.  
  919. ---------------------------
  920.  
  921. >From erichsen@pacificnet.net (Erichsen)
  922. Subject: Q: Open-Close PPP from Code?
  923. Date: Wed, 27 Sep 1995 14:19:14 -0700
  924. Organization: Disorganized
  925.  
  926. Is there any way to open and close a MacPPP connection programmatically?
  927. I'd like to manually open, soft close, and hard close PPP without having
  928. to go to the control panel.
  929.  
  930. +++++++++++++++++++++++++++
  931.  
  932. >From Dave Overton <doverton@iglou.com>
  933. Date: Thu, 28 Sep 1995 14:03:25 GMT
  934. Organization: DataStream Imaging Systems, Inc.
  935.  
  936. If you look at the code to the MacPPP Control Panel,
  937. it will tell you how to do this.
  938.  
  939. This code is extracted from the cdev source.
  940.  
  941.                 case SOFTCLOSEBTN:
  942.                 case HARDCLOSEBTN:
  943.                         if ( Gestalt((OSType) 'PPP ', (long *) &lap) == noErr) {
  944.                                 if (lap && lap->lapClose && lap->transProc) {
  945.                                         (*(lap->lapClose))(lap);        /* close PPP */
  946.                                         if ( (item - numitems) == SOFTCLOSEBTN) {
  947.                                                 lap->ppp_flags |= CLOSE_PPP;
  948.                                                 (*(lap->transProc))(TransitionOpen);
  949.                                         }
  950.                                         updatecp(p, dlogp, numitems);
  951.                                 }
  952.                         }
  953.                         break;
  954.         
  955.                 case OPENBTN:
  956.                         if ( Gestalt((OSType) 'PPP ', (long *) &lap) == noErr) {
  957.                                 if (lap) {
  958.                                         if (lap->transProc == nil) {
  959.                                                 if (noErr == OpenDriver("\p.IPP",&type)) {      /* open TCP */
  960.                                                 CntrlParam tiopb;
  961. #define ipctlGetAddr            15                      /* csCode to get our IP address */
  962.                                                         bzero((b_8 *)&tiopb, sizeof(tiopb));
  963.                                                         tiopb.ioCRefNum = type;
  964.                                                         tiopb.csCode = ipctlGetAddr;
  965.                                                         PBControl((ParamBlockRec *) &tiopb, false);
  966.                                                 }
  967.                                         } else
  968.                                                 (*(lap->transProc))(TransitionOpen);
  969.                                         updatecp(p, dlogp, numitems);
  970.                                 }
  971.                         }
  972.                         break;
  973.  
  974. Dave Overton
  975.  
  976. +++++++++++++++++++++++++++
  977.  
  978. >From rocknrog@intac.com (Roger D. Placer)
  979. Date: Fri, 29 Sep 1995 15:51:54 -0400
  980. Organization: Virtuoso Software Consulting
  981.  
  982. In article <DFMCDp.EML@iglou.com>, Dave Overton <doverton@iglou.com> wrote:
  983.  
  984. > This code is extracted from the cdev source.
  985. >                 case SOFTCLOSEBTN:
  986. >                 case HARDCLOSEBTN:
  987.  
  988.  
  989. [re: PPP soft close and hard close]
  990.  
  991. I always wondered what the hell the difference was, and unless there's
  992. some critical source missing that would contradict what was quoted, it
  993. would appear that they both execute the exact same code. Funky!
  994.  
  995. +++++++++++++++++++++++++++
  996.  
  997. >From erichsen@pacificnet.net (Erichsen)
  998. Date: Fri, 29 Sep 1995 13:27:02 -0700
  999. Organization: Disorganized
  1000.  
  1001. In article <rocknrog-2909951551540001@blmfld-s5.intac.com>,
  1002. rocknrog@intac.com (Roger D. Placer) wrote:
  1003.  
  1004. >I always wondered what the hell the difference was, and unless there's
  1005. >some critical source missing that would contradict what was quoted, it
  1006. >would appear that they both execute the exact same code. Funky!
  1007.  
  1008. If you soft close, the next time a program tries to open PPP, it will try
  1009. to re-connect. If it was hard closed, it won't.
  1010.  
  1011. If you look, it does this on a soft close in addition to all the stuff it
  1012. does on a hard close (From the MacPPP source):
  1013.  
  1014. if( ( item - numitems ) == SOFTCLOSEBTN )
  1015. {
  1016.     lap->ppp_flags |= CLOSE_PPP;
  1017.     ( *( lap->transProc ) )( TransitionOpen );
  1018. }
  1019.  
  1020. This appears to be the only difference, programmatically, from a soft or
  1021. hard close.
  1022.  
  1023. ---------------------------
  1024.  
  1025. >From andrewwelc@aol.com (AndrewWelc)
  1026. Subject: QuickTime JPEG help
  1027. Date: 20 Sep 1995 08:48:47 -0400
  1028. Organization: America Online, Inc. (1-800-827-6364)
  1029.  
  1030. I'm attempting to use QuickTime's Image Compression Manager to display
  1031. generic, cross-platform JPEG images.  It looks simple enough: just use the
  1032. FDecompressImage() routine with a custom proc to spool the JPEG data from
  1033. the file.
  1034.  
  1035. However this routine expects an ImageDescriptionHandle that tells it
  1036. certain things about the image, such as the compressor that was used, the
  1037. size of the image, the resolution, etc.
  1038.  
  1039. So the question is: is there any kind of a built-in routine that will
  1040. extract this information from a generic JPEG file for me, or do I have to
  1041. go in and munge around in the JPEG, building the ImageDescriptionHandle
  1042. myself?
  1043.  
  1044. Any help would be most appreciated.
  1045.  
  1046.  
  1047. Regards,
  1048.  
  1049. Andrew Welch
  1050. Thaumaturgist
  1051. Ambrosia Software, Inc.
  1052.  
  1053. ..........
  1054.  
  1055. For the latest versions of our software, technical support, and Ambrosia
  1056. news, stop by and visit the Ambrosia Software, Inc. support forums:
  1057.  
  1058. America Online ---> Keyword: Ambrosia
  1059.     CompuServe ---> GO word: Ambrosia
  1060.         eWorld --> Shortcut: Ambrosia
  1061.  
  1062. +++++++++++++++++++++++++++
  1063.  
  1064. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro)
  1065. Date: Fri, 22 Sep 1995 16:11:14 +1200
  1066. Organization: University of Waikato
  1067.  
  1068. In article <43p2jf$dgr@newsbf02.news.aol.com>, andrewwelc@aol.com
  1069. (AndrewWelc) wrote:
  1070.  
  1071. >I'm attempting to use QuickTime's Image Compression Manager to display
  1072. >generic, cross-platform JPEG images.  It looks simple enough: just use the
  1073. >FDecompressImage() routine with a custom proc to spool the JPEG data from
  1074. >the file.
  1075. >
  1076. >However this routine expects an ImageDescriptionHandle that tells it
  1077. >certain things about the image, such as the compressor that was used, the
  1078. >size of the image, the resolution, etc.
  1079. >
  1080. >So the question is: is there any kind of a built-in routine that will
  1081. >extract this information from a generic JPEG file for me, or do I have to
  1082. >go in and munge around in the JPEG, building the ImageDescriptionHandle
  1083. >myself?
  1084.  
  1085. You have to munge around in the JPEG and build the ImageDescriptionHandle
  1086. yourself. Here's a routine to extract the bounds of the image:
  1087.  
  1088.     PROCEDURE FindPictureSize
  1089.       (
  1090.         JpegData : ADDRESS;
  1091.         JpegDataSize : LONGCARD;
  1092.         VAR PictureSize : Point
  1093.       );
  1094.       (* scans the JPEG data, looking for the information about
  1095.         the dimensions of the image. *)
  1096.  
  1097.         VAR
  1098.             NextByte, DataEnd : ADDRESS;
  1099.             TwoBytes :
  1100.                 RECORD
  1101.                 CASE : CARDINAL OF
  1102.                 | 1:
  1103.                     HighByte, LowByte : BYTE;
  1104.                 | 2:
  1105.                     SignedWord : ShortInt
  1106.                 END (*CASE*)
  1107.                 END (*RECORD*);
  1108.  
  1109.     BEGIN
  1110.         NextByte := JpegData;
  1111.         DataEnd := JpegData + JpegDataSize;
  1112.         LOOP
  1113.             IF NextByte = DataEnd THEN
  1114.                 ErrorLiteral('couldn’t determine JPEG image bounds',
  1115. ProcessingError);
  1116.                 EXIT
  1117.             END (*IF*);
  1118.             IF ORD(NextByte^) = 0FFH THEN
  1119.                 INC(NextByte);
  1120.                 IF NextByte = DataEnd THEN
  1121.                     ErrorLiteral('malformed JPEG file', ProcessingError);
  1122.                     EXIT
  1123.                 END (*IF*);
  1124.                 IF ORD(NextByte^) = 0C0H THEN
  1125.                     INC(NextByte);
  1126.                     IF DataEnd - NextByte >= 7 THEN
  1127.                         NextByte := NextByte + 3;
  1128.                         TwoBytes.HighByte := NextByte^;
  1129.                         INC(NextByte);
  1130.                         TwoBytes.LowByte := NextByte^;
  1131.                         INC(NextByte);
  1132.                         PictureSize.v := TwoBytes.SignedWord;
  1133.                         TwoBytes.HighByte := NextByte^;
  1134.                         INC(NextByte);
  1135.                         TwoBytes.LowByte := NextByte^;
  1136.                         INC(NextByte);
  1137.                         PictureSize.h := TwoBytes.SignedWord;
  1138.                         EXIT
  1139.                     ELSE
  1140.                         ErrorLiteral('malformed bounds info', ProcessingError);
  1141.                         EXIT
  1142.                     END (*IF*)
  1143.                 END (*IF*)
  1144.             ELSE
  1145.                 INC(NextByte)
  1146.             END (*IF*)
  1147.         END (*LOOP*)
  1148.     END FindPictureSize;
  1149.  
  1150. +++++++++++++++++++++++++++
  1151.  
  1152. >From quinn@quinn.echidna.id.au (Quinn "The Eskimo!")
  1153. Date: Fri, 22 Sep 1995 12:08:55 +0800
  1154. Organization: Underemployed, and loving it!
  1155.  
  1156. In article <43p2jf$dgr@newsbf02.news.aol.com>, andrewwelc@aol.com
  1157. (AndrewWelc) wrote:
  1158.  
  1159. >So the question is: is there any kind of a built-in routine that will
  1160. >extract this information from a generic JPEG file for me, or do I have to
  1161. >go in and munge around in the JPEG, building the ImageDescriptionHandle
  1162. >myself?
  1163.  
  1164. Aaron Giles' JPEG library (on the Apprentice CD and most probably
  1165. elsewhere) demonstrates this.
  1166.  
  1167. Share and Enjoy.
  1168. --
  1169. Quinn "The Eskimo!"       <http://www.quinn.echidna.id.au/Quinn/WWW/>
  1170.   "Not now Blaznee, I'm busy sealing the doom of countless millions."
  1171.     Note the new email address. Check my web page for the full story.
  1172.  
  1173. +++++++++++++++++++++++++++
  1174.  
  1175. >From tgl@netcom.com (Tom Lane)
  1176. Date: Sat, 23 Sep 1995 15:57:29 GMT
  1177. Organization: Netcom Online Communications Services
  1178.  
  1179. ldo@waikato.ac.nz (Lawrence D'Oliveiro) writes:
  1180. > You have to munge around in the JPEG and build the ImageDescriptionHandle
  1181. > yourself. Here's a routine to extract the bounds of the image:
  1182. >     [ code omitted ]
  1183.  
  1184. The code Lawrence posted is dangerously oversimplified.  It will fail if
  1185. the JPEG file uses a non-baseline SOF marker.  (SOF1, FFC1, is reasonably
  1186. common; SOF2, FFC2, will soon be common with the spread of progressive
  1187. JPEGs.)  Worse, it can be fooled by an FFC0 sequence that happens to occur
  1188. within the body of some other marker.  For example, if fed a JPEG image
  1189. that contains a JPEG-compressed thumbnail per the JFIF 1.02 spec, this
  1190. code will return the dimensions of the thumbnail rather than of the main
  1191. image.
  1192.  
  1193. You can find code to do it right in any number of places.  A heavily
  1194. commented C version is in the file rdjpgcom.c in the IJG code
  1195. (ftp.uu.net:/graphics/jpeg/jpegsrc.v6.tar.gz).  Aaron Giles posted
  1196. Mac-specific code many moons ago.  I dunno if Aaron's code is still
  1197. available on the net, but I think it's on the Apprentice CD for Mac
  1198. developers.  Apple themselves probably provide suitable code somewhere
  1199. in their QuickTime developer info.
  1200.  
  1201.                         regards, tom lane
  1202.                         organizer, Independent JPEG Group
  1203.  
  1204. +++++++++++++++++++++++++++
  1205.  
  1206. >From 100336.230@compuserve.com (Faustino Forcén)
  1207. Date: 24 Sep 1995 03:28:34 GMT
  1208. Organization: VEGA & Asociados
  1209.  
  1210. In article <43p2jf$dgr@newsbf02.news.aol.com>, andrewwelc@aol.com
  1211. (AndrewWelc) wrote:
  1212.  
  1213. > So the question is: is there any kind of a built-in routine that will
  1214. > extract this information from a generic JPEG file for me, or do I have to
  1215. > go in and munge around in the JPEG, building the ImageDescriptionHandle
  1216. > myself?
  1217.  
  1218. Andrew
  1219. I didn´t wrote the original code. I took it from AppleLink and adapted it
  1220. to my own set of image reading/writing classes.
  1221.  
  1222. BTW, the JPEG images created with QuickTime are PICT files, but the data
  1223. (once passed the 512 bytes header) is a JFIF file.
  1224.  
  1225. hope it helps
  1226.  
  1227. Faustino Forcén
  1228. Bugmeister
  1229. Vega & Asociados
  1230.  
  1231.  
  1232.  
  1233. #define JFIF_ID_MARKER     0xE0
  1234. #define JFIF_INFO_MARKER   0xC0
  1235.  
  1236. // miFile      : Original file
  1237. // dim         : destination size for the image
  1238. // miOffscreen : where to put the image
  1239. // invierte    : if I want to invert the palette.
  1240. OSErr TJPEG::GetImagen(FSSpec miFile, Rect *dim, GWorldPtr *miOffScreen,
  1241. Boolean invierte)
  1242. {
  1243. Rect     srcRect, destRect;
  1244. GDHandle    gdh;
  1245. CGrafPtr    port;
  1246. Byte     *data = nil, *s, id[5] = "JFIF";
  1247. long     length, i;
  1248. short       j, refnum, err, width, height;
  1249. Point    imagenSize;
  1250. PixMapHandle pix;
  1251. ImageDescriptionHandle descH;
  1252. short    modo;
  1253.  
  1254.    if (*miOffScreen)
  1255.       DisposeGWorld(*miOffScreen);
  1256.    *miOffScreen = nil;
  1257.  
  1258.    err = FSpOpenDF(&miFile, fsRdPerm, &refnum);
  1259.    if (!err)
  1260.    {
  1261.       err = GetEOF(refnum, &length);
  1262.       if (!err && length < 170L)
  1263.          err = -1;
  1264.       if (!err)
  1265.       {
  1266.          data = (Byte*)NewPtr(length);
  1267.          if (!data)
  1268.             err = memFullErr;
  1269.       }
  1270.       if (!err)
  1271.          err = FSRead(refnum, &length, data);
  1272.       FSClose(refnum);
  1273.    }
  1274.  
  1275.    if (!err)
  1276.    {
  1277.       // make sure data is JFIF data stream
  1278.       for (i = 0; i < length; ++i)
  1279.       {
  1280.          if (data[i] == 0xFF && data[i+1] == JFIF_ID_MARKER)
  1281.          {
  1282.             for (s = &data[i+4], j = 0; j < 5; ++s, ++j)
  1283.             {
  1284.                if (*s != id[j])
  1285.                {
  1286.                   err = -1;
  1287.                   j = 5;
  1288.                }
  1289.             }
  1290.             i = length;
  1291.          }
  1292.       }
  1293.       if (err)
  1294.          goto abortJPEG;
  1295.  
  1296.       // read JPEG height and width from JFIF stream
  1297.       err = -1;
  1298.       for (i = 0; i < length; ++i)
  1299.       {
  1300.          if (data[i] == 0xFF && data[i+1] == JFIF_INFO_MARKER)
  1301.          {
  1302.             height = data[i+5]*256 + data[i+6];
  1303.             width = data[i+7]*256 + data[i+8];
  1304.             err = noErr;
  1305.             i = length;
  1306.          }
  1307.       }
  1308.       if (!err)
  1309.       {
  1310.          srcRect.top = 0;
  1311.          srcRect.left = 0;
  1312.          srcRect.bottom = height;
  1313.          srcRect.right = width;
  1314.  
  1315.          imagenSize.h = srcRect.right;
  1316.          imagenSize.v = srcRect.bottom;
  1317.       
  1318.          // hay que calcular el tamaño optimo para escalar
  1319.          calculaRect(&destRect, &imagenSize, dim, escalaBoth);
  1320.  
  1321.          err = NewGWorld(miOffScreen, 24, &destRect, nil, nil, 0);
  1322.  
  1323.          GetGWorld(&port, &gdh);
  1324.          SetGWorld(*miOffScreen, nil);
  1325.          ClipRect(&destRect);
  1326.  
  1327.          ForeColor(blackColor);
  1328.          BackColor(whiteColor);
  1329.  
  1330.             // a brand new imgdeschdl based on the jfif data
  1331.          descH = (ImageDescriptionHandle)NewHandle(sizeof(ImageDescription));
  1332.          HLock((Handle)descH);
  1333.          (*descH)->idSize = sizeof(ImageDescription);
  1334.          (*descH)->cType = 'jpeg';  
  1335.          (*descH)->resvd1 = 0L;
  1336.          (*descH)->resvd2 = 0;
  1337.          (*descH)->dataRefIndex = 0;
  1338.          (*descH)->version = 1;
  1339.          (*descH)->revisionLevel = 1;
  1340.          (*descH)->vendor = 'appl';
  1341.          (*descH)->temporalQuality = 0;
  1342.          (*descH)->spatialQuality = 0;
  1343.          (*descH)->width = width;
  1344.          (*descH)->height = height;
  1345.          (*descH)->vRes = (*descH)->hRes = Long2Fix(72L);
  1346.          (*descH)->dataSize = length;
  1347.          (*descH)->frameCount = 1;
  1348.          BlockMove("\pPhoto - JPEG", (*descH)->name, 32L);
  1349.          (*descH)->depth = 24;
  1350.          (*descH)->clutID = -1;
  1351.          HUnlock((Handle)descH);
  1352.  
  1353.          pix = GetGWorldPixMap(*miOffScreen);
  1354.          
  1355.             // invierte is for some agency images that have an inverted palette
  1356.          if(invierte)
  1357.             modo = ditherCopy + notSrcCopy;
  1358.          else
  1359.             modo = ditherCopy;
  1360.  
  1361.          if (LockPixels(pix))
  1362.          {
  1363.             err = DecompressImage((Ptr)data, descH, pix, 
  1364.                            &srcRect, &destRect, modo, nil);          
  1365.             UnlockPixels(pix);
  1366.          }
  1367.          else
  1368.             err = memFullErr;
  1369.  
  1370.          SetGWorld(port, gdh);   // restore port and device
  1371.  
  1372.          DisposeHandle((Handle)descH);
  1373.       }
  1374.    }
  1375.  
  1376. abortJPEG:
  1377.    if (data)
  1378.       DisposePtr((Ptr)data);
  1379.  
  1380.    return err;
  1381. }
  1382.  
  1383. // eof
  1384.  
  1385. -- 
  1386. Blenders of good code since 1988
  1387.  
  1388. ---------------------------
  1389.  
  1390. >From winterp@spot.Colorado.EDU (WINTER  PAUL RUDOLPH)
  1391. Subject: Storing data in text portion of an application
  1392. Date: 27 Sep 95 17:37:31 GMT
  1393. Organization: University of Colorado at Boulder
  1394.  
  1395. I have a protocal question:
  1396.  
  1397. Is it proper to store data in the data portion of an application?  There is
  1398. too much of it to comfortably store it as resources, so that option is not
  1399. available.  At the start of the program, the application would open is data
  1400. fork, read in the data, and then close it again.  Is this proper, and if so,
  1401. how dangerous is it to the integrity of the application?
  1402.  
  1403. Thanks for any advice/thoughts on this.  If it can't/shouldn't be done I can
  1404. always stick with the external file that must be kept with the program.
  1405.  
  1406. Paul Winter
  1407.  
  1408. +++++++++++++++++++++++++++
  1409.  
  1410. >From pandhphot@aol.com (PandH Phot)
  1411. Date: 27 Sep 1995 17:07:06 -0400
  1412. Organization: America Online, Inc. (1-800-827-6364)
  1413.  
  1414. This is an opinion, not a fact. I have done what you say, and it works
  1415. just fine. But as a USER of software I REALLY HATE apps that do this. They
  1416. always seem to end up destroying themselves during a poorly-timed crash.
  1417. Frankly, modifying the app's resource fork during operation has the same
  1418. limitation, and I could live without that, too.
  1419.  
  1420. I much prefer the use of some sort of external file (preferences or some
  1421. such).
  1422.  
  1423. But as I say, it's an opinion.
  1424.  
  1425. paul
  1426.  
  1427. +++++++++++++++++++++++++++
  1428.  
  1429. >From "Andrew C. Plotkin" <erkyrath+@CMU.EDU>
  1430. Date: Wed, 27 Sep 1995 17:05:39 -0400
  1431. Organization: Carnegie Mellon, Pittsburgh, PA
  1432.  
  1433. winterp@spot.Colorado.EDU (WINTER  PAUL RUDOLPH) writes:
  1434. > Is it proper to store data in the data portion of an application?  There is
  1435. > too much of it to comfortably store it as resources, so that option is not
  1436. > available.  At the start of the program, the application would open is data
  1437. > fork, read in the data, and then close it again.  Is this proper, and if so,
  1438. > how dangerous is it to the integrity of the application?
  1439.  
  1440. There's nothing specifically wrong with it. However, it's a great pain
  1441. to do in a PPC native or fat application. The PPC code is stored in
  1442. the data fork, and you'd have to diddle the code fragment resource to
  1443. make sure the PPC code and your data don't overlap. I don't know if
  1444. there are any development systems which arrange this for you
  1445. automatically. 
  1446.  
  1447. You'd be amazed how much data can be stored in the resource fork,
  1448. though. I've got a 6-meg resource file in the project I'm working on
  1449. now.  The only disadvantage is that it's hard to read in just part of
  1450. a resource -- but since you say you're reading all the data at the
  1451. start of the program, that shouldn't concern you.
  1452.  
  1453. --Z
  1454.  
  1455. "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
  1456.  
  1457. +++++++++++++++++++++++++++
  1458.  
  1459. >From "Andrew C. Plotkin" <erkyrath+@CMU.EDU>
  1460. Date: Wed, 27 Sep 1995 18:53:23 -0400
  1461. Organization: Carnegie Mellon, Pittsburgh, PA
  1462.  
  1463. pandhphot@aol.com (PandH Phot) writes:
  1464. > This is an opinion, not a fact. I have done what you say, and it works
  1465. > just fine. But as a USER of software I REALLY HATE apps that do this. They
  1466. > always seem to end up destroying themselves during a poorly-timed crash.
  1467. > Frankly, modifying the app's resource fork during operation has the same
  1468. > limitation, and I could live without that, too.
  1469.  
  1470. I assume you're talking about *modifying* the application's data fork
  1471. as it runs. I agree that that is absolutely to be avoided at all
  1472. costs. But I think the original poster just meant storing some
  1473. read-only data in the data fork.
  1474.  
  1475. --Z
  1476.  
  1477. "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
  1478.  
  1479. +++++++++++++++++++++++++++
  1480.  
  1481. >From triple@nando.net (Joe Zobkiw)
  1482. Date: Wed, 27 Sep 1995 20:30:01 -0400
  1483. Organization: TripleSoft Inc.
  1484.  
  1485. In article <winterp.812223451@spot.Colorado.EDU>,
  1486. winterp@spot.Colorado.EDU (WINTER  PAUL RUDOLPH) wrote:
  1487.  
  1488. >Is it proper to store data in the data portion of an application?  There is
  1489. >too much of it to comfortably store it as resources, so that option is not
  1490. >available.  At the start of the program, the application would open is data
  1491. >fork, read in the data, and then close it again.  Is this proper, and if so,
  1492. >how dangerous is it to the integrity of the application?
  1493.  
  1494. This is perfectly legitimate EXCEPT that by default PowerPC code is stored
  1495. in the data fork of native applications. Mind you, you can change the way
  1496. this works (store your PowerPC code in a resource, for example) but then
  1497. you lose some of the advantages of data fork resident code such as Virtual
  1498. Memory paging, etc.
  1499.  
  1500. I would suggest creating a separate file called "Application Data" or
  1501. somesuch, place it in the same folder as the application, and read from it
  1502. instead.
  1503.  
  1504. Joe Zobkiw
  1505. President
  1506.  
  1507. - ----------------------------------------------------------------
  1508. TripleSoft Inc, Macintosh Software Development     CIS: 74631,1700
  1509. P.O. Box 30774, Raleigh, NC 27622-0774      AOL/eWorld: TripleSoft
  1510. voice/fax (919) 872-0916                Internet: Triple@nando.net
  1511. - ----------------------------------------------------------------
  1512.  Look for "A Fragment of Your Imagination" from Addison-Wesley...
  1513. PowerPC/Code Resources/Fragments/Components/Extensions/and more...
  1514.  
  1515. +++++++++++++++++++++++++++
  1516.  
  1517. >From winterp@spot.Colorado.EDU (WINTER  PAUL RUDOLPH)
  1518. Date: 28 Sep 95 14:57:50 GMT
  1519. Organization: University of Colorado at Boulder
  1520.  
  1521.  
  1522. >>Is it proper to store data in the data portion of an application?  There is
  1523. >>too much of it to comfortably store it as resources, so that option is not
  1524. >>available.  At the start of the program, the application would open is data
  1525. >>fork, read in the data, and then close it again.  Is this proper, and if so,
  1526. >>how dangerous is it to the integrity of the application?
  1527.  
  1528. >This is perfectly legitimate EXCEPT that by default PowerPC code is stored
  1529. >in the data fork of native applications. Mind you, you can change the way
  1530. >this works (store your PowerPC code in a resource, for example) but then
  1531. >you lose some of the advantages of data fork resident code such as Virtual
  1532. >Memory paging, etc.
  1533.  
  1534. The application I am working on will not becreated specificaly for a Power
  1535. PC, as I don't have access to a compiler which creates aps for PowerPC. 
  1536. This being the case, do I still have to worry about code in the data fork?
  1537. >From all the responses I've gotten, I'm inclined to stick with the external
  1538. file, but I'm just curious now.
  1539.  
  1540. Thanks to everyone who responded!!!
  1541.  
  1542. Paul Winter
  1543.  
  1544.  
  1545. ---------------------------
  1546.  
  1547. >From eddyg@vcd.hp.com (Eddy J. Gurney)
  1548. Subject: Why doesn't the Dialog Manager recognize I moved some controls?
  1549. Date: 11 Sep 1995 17:55:32 GMT
  1550. Organization: Hewlett-Packard
  1551.  
  1552. I have a dialog box with several buttons in it. In some cases, I would
  1553. like to swap the location of two buttons. I easily accomplish this with
  1554. a couple of calls to MoveControl() after I've called GetNewDialog() and
  1555. before I show it. The controls *look* like they've swapped locations,
  1556. but when the user clicks on them (or points to them with Balloon Help
  1557. active), the Dialog Manager tells me they clicked on the "original"
  1558. button.
  1559.  
  1560. Example:
  1561.  
  1562. The dialog buttons are stored (and sometimes used) like this:
  1563.  
  1564.                ( Cancel )  (   OK   )
  1565.  
  1566. So I call MoveControl to put the OK button where the Cancel button is
  1567. and the Cancel button where the OK button is:
  1568.     
  1569.                (   OK   )  ( Cancel )
  1570.  
  1571. But now when the user clicks on "OK", the Dialog Manager tells me they
  1572. clicked on Cancel and vice versa.  I don't understand this; aftera all,
  1573. the OK button is still item 1 and the Cancel button still item 2, just
  1574. in new locations.
  1575.  
  1576. Any ideas?
  1577.  
  1578. Thanks,
  1579. Eddy
  1580.  
  1581. P.S. Please don't tell me this is bad UI and that I shouldn't be doing
  1582.      this. I already know that. I just want to know that answer to this
  1583.      problem. ;-)
  1584.  
  1585. +++++++++++++++++++++++++++
  1586.  
  1587. >From dstone@chem.utoronto.ca (David Stone)
  1588. Date: Mon, 11 Sep 1995 18:27:08 GMT
  1589. Organization: University of Toronto Chemistry
  1590.  
  1591. In article <431t6k$97e@news.vcd.hp.com>, eddyg@vcd.hp.com (Eddy J. Gurney)
  1592. wrote:
  1593. > I have a dialog box with several buttons in it. In some cases, I would
  1594. > like to swap the location of two buttons. I easily accomplish this with
  1595. > a couple of calls to MoveControl() after I've called GetNewDialog() and
  1596. > before I show it. The controls *look* like they've swapped locations,
  1597. > but when the user clicks on them (or points to them with Balloon Help
  1598. > active), the Dialog Manager tells me they clicked on the "original"
  1599. > button.
  1600. ====snip=====
  1601.  
  1602. The dialog manager keeps its own list of DITL items that includes their
  1603. rects.  This list is unaffected by MoveControl and so the dialog manager
  1604. continues to believe that the items are where they were originally.
  1605.  
  1606. > P.S. Please don't tell me this is bad UI and that I shouldn't be doing
  1607. >      this. I already know that. I just want to know that answer to this
  1608. >      problem. ;-)
  1609.  
  1610. OK, I won't!  My guess would be you'd have to use AppendDITL and
  1611. ShortenDITL
  1612. to move them, ie. physically take the items out of the DITL, and add them
  1613. back in with the new position.  An easier thing to do might be to implement
  1614. a "state" variable which flags which positions you are using for the
  1615. buttons, then simply swap the control titles.  Of course, you'll have to
  1616. switch the itemHit value depending on the "state" flag, which is still
  1617. ugly.  And you'll also have to deal with complaints about items moving
  1618. from your users, but there you go.
  1619.  
  1620. Dave Stone
  1621.  
  1622. +++++++++++++++++++++++++++
  1623.  
  1624. >From resorcerer@aol.com (Resorcerer)
  1625. Date: 12 Sep 1995 00:58:49 -0400
  1626. Organization: America Online, Inc. (1-800-827-6364)
  1627.  
  1628. Eddy -
  1629.  
  1630. >The controls *look* like they've swapped locations,
  1631. >but when the user clicks on them (or points to them with Balloon Help
  1632. >active), the Dialog Manager tells me they clicked on the "original"
  1633. >button.
  1634.  
  1635. You have to move the controls (ControlHandles) as well as the Control
  1636. items in the dialog's item list.  The Control items are what the Dialog
  1637. Manager and Help Manager pay attention to, but the ControllHandles are
  1638. what the window updating pays attention to.
  1639.  
  1640. Doug McKenna
  1641. Mathemaesthetics, Inc.
  1642.  
  1643. PS. Try this routine to see if it works...
  1644.  
  1645. void PlaceDialogControlItem(DialogPtr dlog, short item, Rect *bounds)
  1646.  {
  1647.   short type; ControlHandle hndl; Rect box;
  1648.   
  1649.   GetDItem(dlog,item,&type,(Handle *)&hndl,&box);
  1650.   
  1651.   type &= ~itemDisable;
  1652.   if (type==(ctrlItem+btnCtrl) || type==(ctrlItem+radCtrl) ||
  1653.    type==(ctrlItem+chkCtrl) || type==(ctrlItem+resCtrl))
  1654.    (*hndl)->contrlRect = *bounds;
  1655.    
  1656.   SetDItem(dlog,item,type,(Handle)hndl,bounds);
  1657.  }
  1658.  
  1659.  
  1660. +++++++++++++++++++++++++++
  1661.  
  1662. >From Richard Wesley <hawkfish@punchdeck.com>
  1663. Date: 12 Sep 1995 14:50:55 GMT
  1664. Organization: Punch Deck Consulting
  1665.  
  1666. dstone@chem.utoronto.ca (David Stone) wrote:
  1667. >In article <431t6k$97e@news.vcd.hp.com>, eddyg@vcd.hp.com (Eddy J. Gurney)
  1668. >wrote:
  1669. >> 
  1670. >> I have a dialog box with several buttons in it. In some cases, I would
  1671. >> like to swap the location of two buttons. I easily accomplish this with
  1672. >> a couple of calls to MoveControl() after I've called GetNewDialog() and
  1673. >> before I show it. The controls *look* like they've swapped locations,
  1674. >> but when the user clicks on them (or points to them with Balloon Help
  1675. >> active), the Dialog Manager tells me they clicked on the "original"
  1676. >> button.
  1677. >====snip=====
  1678. >
  1679. >The dialog manager keeps its own list of DITL items that includes their
  1680. >rects.  This list is unaffected by MoveControl and so the dialog manager
  1681. >continues to believe that the items are where they were originally.
  1682.  
  1683. Exactly.
  1684.  
  1685. >
  1686. >> 
  1687. >> P.S. Please don't tell me this is bad UI and that I shouldn't be doing
  1688. >>      this. I already know that. I just want to know that answer to this
  1689. >>      problem. ;-)
  1690. >
  1691. >OK, I won't!  My guess would be you'd have to use AppendDITL and
  1692. >ShortenDITL
  1693. >to move them, ie. physically take the items out of the DITL, and add them
  1694. >back in with the new position.  An easier thing to do might be to implement
  1695.  
  1696. This is like using tactical nuclear weapons to kill a fly.  Just do a
  1697.  
  1698. ::GetDialogItem
  1699. ::SetDialogItem
  1700.  
  1701. and change the Rect argument between the calls.  You might find it useful
  1702. to call ::HideDialogItem and ::ShowDialogItem while you move things around.
  1703. Don't forget about ::S/GetDefaultItem and ::S/GetCancelItem and moving your
  1704. hilite item.
  1705.  
  1706. >a "state" variable which flags which positions you are using for the
  1707. >buttons, then simply swap the control titles.  Of course, you'll have to
  1708. >switch the itemHit value depending on the "state" flag, which is still
  1709. >ugly.  And you'll also have to deal with complaints about items moving
  1710. >from your users, but there you go.
  1711.  
  1712. This is likely to be confusing for everybody and won't fix the Balloon
  1713. Help problem.
  1714.  
  1715. - rmgw
  1716.  
  1717. Who hasn't looked at the Dialog Manager in years until he had to write yet
  1718. another lightweight UI framework based on it last week...
  1719.  
  1720. http://www.punchdeck.com/hawkfish/PunchDeck.html
  1721.  
  1722. - --------------------------------------------------------------------------
  1723. Richard Wesley  hawkfish@punchdeck.com | "'Hand it round first, and cut it
  1724. Punch Deck Consulting pnchdeck@aol.com |  afterwards.'" - Lewis Carroll,
  1725.      Macintosh Software Development    |    "Through the Looking Glass"
  1726. - --------------------------------------------------------------------------
  1727.  
  1728.  
  1729.  
  1730. +++++++++++++++++++++++++++
  1731.  
  1732. >From dstone@chem.utoronto.ca (David Stone)
  1733. Date: Tue, 12 Sep 1995 18:12:30 GMT
  1734. Organization: University of Toronto Chemistry
  1735.  
  1736. In article <4346of$666@news.halcyon.com>, Richard Wesley
  1737. <hawkfish@punchdeck.com> wrote:
  1738. > dstone@chem.utoronto.ca (David Stone) wrote:
  1739. > >In article <431t6k$97e@news.vcd.hp.com>, eddyg@vcd.hp.com (Eddy J. Gurney)
  1740. > >wrote:
  1741.  
  1742. ===snip====
  1743.  
  1744. > >OK, I won't!  My guess would be you'd have to use AppendDITL and
  1745. > >ShortenDITL
  1746. > >to move them, ie. physically take the items out of the DITL, and add them
  1747. > >back in with the new position.  An easier thing to do might be to implement
  1748. > This is like using tactical nuclear weapons to kill a fly.  Just do a
  1749. > ::GetDialogItem
  1750. > ::SetDialogItem
  1751.  
  1752. Duh!  Of course, I could always claim that I was deliberately making it
  1753. hard to discourage "improper" user interface activities.  Now where have
  1754. I seen that tactic before.....
  1755.  
  1756. Dave Stone
  1757.  
  1758. +++++++++++++++++++++++++++
  1759.  
  1760. >From David Shortt <wyatt@wyatt.com>
  1761. Date: 13 Sep 1995 06:05:01 GMT
  1762. Organization: Wyatt Technology Corp.
  1763.  
  1764. >In article <431t6k$97e@news.vcd.hp.com>, eddyg@vcd.hp.com (Eddy J. Gurney)
  1765. >wrote:
  1766. >> 
  1767. >> I have a dialog box with several buttons in it. In some cases, I would
  1768. >> like to swap the location of two buttons. I easily accomplish this with
  1769. >> a couple of calls to MoveControl() after I've called GetNewDialog() and
  1770. >> before I show it. The controls *look* like they've swapped locations,
  1771. >> but when the user clicks on them (or points to them with Balloon Help
  1772. >> active), the Dialog Manager tells me they clicked on the "original"
  1773. >> button.
  1774.  
  1775. I use the following routine:
  1776.  
  1777.  procedure MoveMyItemRel (theDialog: dialogPtr;
  1778.        itemNum: integer;
  1779.        dh, dv: integer);
  1780. {moves a dialog control item by (dh,dv)}
  1781.   var
  1782.    theType: integer;
  1783.    theHandle: handle;
  1784.    theBox: rect;
  1785.  begin
  1786.   GetDialogItem(theDialog, itemNum, theType, theHandle, theBox);
  1787.   if BAND(theType, ctrlItem) = ctrlItem then
  1788.    MoveControl(ControlHandle(theHandle), theBox.left + dh, theBox.top + dv);
  1789.   with theBox do begin
  1790.    left := left + dh;
  1791.    right := right + dh;
  1792.    top := top + dv;
  1793.    bottom := bottom + dv;
  1794.   end;
  1795.   SetDialogItem(theDialog, itemNum, theType, theHandle, theBox);
  1796.  end;
  1797.  
  1798. I found that I had to move the control _and_ call SetDialogItem.  Hope this helps.
  1799.  
  1800. Dave Shortt
  1801. wyatt@wyatt.com
  1802.  
  1803.  
  1804.  
  1805.  
  1806. +++++++++++++++++++++++++++
  1807.  
  1808. >From mouser@zercom.net (Martin-Gilles Lavoie)
  1809. Date: Wed, 27 Sep 1995 20:54:33 -0500
  1810. Organization: nil
  1811.  
  1812. In article <435sad$bs3@ocean.silcom.com>, David Shortt <wyatt@wyatt.com> wrote:
  1813.  
  1814. > >In article <431t6k$97e@news.vcd.hp.com>, eddyg@vcd.hp.com (Eddy J. Gurney)
  1815. > >wrote:
  1816. > >> 
  1817. > >> I have a dialog box with several buttons in it. In some cases, I would
  1818. > >> like to swap the location of two buttons. I easily accomplish this with
  1819. > >> a couple of calls to MoveControl() after I've called GetNewDialog() and
  1820. > >> before I show it. The controls *look* like they've swapped locations,
  1821. > >> but when the user clicks on them (or points to them with Balloon Help
  1822. > >> active), the Dialog Manager tells me they clicked on the "original"
  1823. > >> button.
  1824. > I use the following routine:
  1825. >  procedure MoveMyItemRel (theDialog: dialogPtr;
  1826. >        itemNum: integer;
  1827. >        dh, dv: integer);
  1828. > {moves a dialog control item by (dh,dv)}
  1829. >   var
  1830. >    theType: integer;
  1831. >    theHandle: handle;
  1832. >    theBox: rect;
  1833. >  begin
  1834. >   GetDialogItem(theDialog, itemNum, theType, theHandle, theBox);
  1835. >   if BAND(theType, ctrlItem) = ctrlItem then
  1836. >    MoveControl(ControlHandle(theHandle), theBox.left + dh, theBox.top + dv);
  1837. >   with theBox do begin
  1838. >    left := left + dh;
  1839. >    right := right + dh;
  1840. >    top := top + dv;
  1841. >    bottom := bottom + dv;
  1842. >   end;
  1843. >   SetDialogItem(theDialog, itemNum, theType, theHandle, theBox);
  1844. >  end;
  1845. > I found that I had to move the control _and_ call SetDialogItem.  Hope
  1846. this helps.
  1847.  
  1848. An answer to this behaviour is that the Dialog Manager looks through it's
  1849. Dialog Item List handle ('ditl') for the first item wich returns true on
  1850. PtInRect() (also giving the dialog manager it's anoying back-to-front
  1851. order).
  1852.  
  1853. Once it finds a targeted rect, it uses it's itemHandle to reference a
  1854. control.  I.e., it doesn't find the control using FindControl().
  1855.  
  1856. MGL
  1857.  
  1858. Martin-Gilles Lavoie
  1859. - ------------------------------------------------------------------------------
  1860.    MPW: Because life is too complicated for CodeWarrior.
  1861. - ------------------------------------------------------------------------------
  1862.  
  1863. ---------------------------
  1864.  
  1865. >From dstone@chem.utoronto.ca (David Stone)
  1866. Subject: [Q] Changing Pixmap resolution???
  1867. Date: Fri, 22 Sep 1995 16:53:44 GMT
  1868. Organization: University of Toronto Chemistry
  1869.  
  1870. Looking at the Pixmap data structure, there are two fields for
  1871. resolution (hRes, vRes, both Fixed).  Is it possible to set these
  1872. to values other than 72 dpi??  Specifically, could I create a Pixmap
  1873. offscreen with the same resolution as a LaserWriter (300 dpi)?
  1874.  
  1875. The reason for asking is problems printing large symbols (up to 0.25")
  1876. in graphs created using quickdraw calls.  If the graph is bigger than
  1877. the page (it usually is), it has to be scaled to fit (typically 87%
  1878. reduction).  When this is done, circles frequently become ellipses
  1879. and squares rectangles on the printed version because of mismatch
  1880. of the pixel locations between the screen and printer page.
  1881. I want to try drawing the graph into a Pixmap at the same resolution 
  1882. as the printer and then Copybits or Open/Close/DrawPicture to the 
  1883. printer page.
  1884.  
  1885. Does Copybits cope with different resolution images?  How?
  1886. I'm already drawing the screen graph offscreen and CopyBitsing it
  1887. into the approriate location - could I Copybits the offscreen
  1888. image (@ 72 dpi) into the printer port (@ 300 dpi)???
  1889.  
  1890. Please email response as well as post.
  1891.  
  1892. David Stone
  1893. dstone@chem.utoronto.ca
  1894.  
  1895. Thanks!
  1896.  
  1897. +++++++++++++++++++++++++++
  1898.  
  1899. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro)
  1900. Date: Tue, 26 Sep 1995 15:55:48 +1200
  1901. Organization: University of Waikato
  1902.  
  1903. In article <dstone-220995125502@csgmac.chem.utoronto.ca>,
  1904. dstone@chem.utoronto.ca (David Stone) wrote:
  1905.  
  1906. >Looking at the Pixmap data structure, there are two fields for
  1907. >resolution (hRes, vRes, both Fixed).  Is it possible to set these
  1908. >to values other than 72 dpi??  Specifically, could I create a Pixmap
  1909. >offscreen with the same resolution as a LaserWriter (300 dpi)?
  1910. ...
  1911. >Does Copybits cope with different resolution images?  How?
  1912. >I'm already drawing the screen graph offscreen and CopyBitsing it
  1913. >into the approriate location - could I Copybits the offscreen
  1914. >image (@ 72 dpi) into the printer port (@ 300 dpi)???
  1915.  
  1916. I don't think the resolution fields in the PixMap mean much with current
  1917. versions of QuickDraw. But yes, you _can_ create QuickDraw pictures
  1918. containing pixels at any resolution you desire. The trick lies in the
  1919. relative dimensions of the srcRect and dstRect arguments to CopyBits: for
  1920. example, if the source rectangle is (0, 0, 300, 300) and the destination
  1921. one is (0, 0, 72, 72), then your source bitmap/pixmap is interpreted as
  1922. having an effective resolution of 300 pixels per inch.
  1923.  
  1924. I was doing this trick with the LaserWriter driver several years ago, and
  1925. it worked a treat. I could generate the 300-dpi bitmaps in my code, paste
  1926. them into Microsoft Word, and print them from there at full quality.
  1927.  
  1928. Of course, if your application is handling the printing directly, you can
  1929. go one better: use PrGeneral to enquire the available printer resolutions,
  1930. set the printer port to a suitably high resolution, and then all your
  1931. drawing into that port will take place at that resolution.
  1932.  
  1933. ---------------------------
  1934.  
  1935. >From st955901@pilot.stu.cowan.edu.au (Philip Cummins)
  1936. Subject: [Q] Traps not callable from interrupt, why?
  1937. Date: Sun, 24 Sep 1995 17:59:38 +0800
  1938. Organization: Edith Cowan University
  1939.  
  1940. Hello,
  1941.  
  1942. Is there any way I can call an a-trap listed as 'do not call from
  1943. interrupt' from an interrupt safely? And what exactly is the reason why we
  1944. can't call them?
  1945.  
  1946. Thanks,
  1947.  
  1948. Philip
  1949.  
  1950. -- 
  1951. Please exert your creativity to convince yourself there's a signature here.
  1952.  
  1953. +++++++++++++++++++++++++++
  1954.  
  1955. >From reinder@neuretp.biol.ruu.nl (Reinder Verlinde)
  1956. Date: Sun, 24 Sep 1995 15:04:15 +0200
  1957. Organization: Rijksuniversiteit Utrecht
  1958.  
  1959. In article <st955901-2409951759380001@ppp29.cowan.edu.au>,
  1960. st955901@pilot.stu.cowan.edu.au (Philip Cummins) wrote:
  1961.  
  1962. ) Hello,
  1963. ) Is there any way I can call an a-trap listed as 'do not call from
  1964. ) interrupt' from an interrupt safely? And what exactly is the reason why we
  1965. ) can't call them?
  1966. You can't call most of them because they may move memory, and the memory
  1967. manager is not reentrant. I guess you could try and hack your way around it
  1968. by creating a heap zone to be used solely by your interrupt routine, and
  1969. doing a SetZone (If SetZone is not interrupt safe this trick does not work)
  1970. to that zone in your interrupt handler. If you do that you should not
  1971. only save the current zone (via a GetZone/SetZone pair), but also the
  1972. current internal state of the memory manager, and that is undocumented.
  1973.  
  1974. You should also ensure not to do anything in the System heap, so calls
  1975. like SetFont, DrawString, maybe even LineTo and PenSize etc. are a nono.
  1976. I don't know whether there will be many routines which can be fixed this
  1977. way.
  1978.  
  1979. Reinder Verlinde
  1980.  
  1981. >From the index of Inside Macintosh:
  1982.    "Human interface Guidelines: see User interface Guidelines"
  1983. I wonder what they are aiming at. Monkeys? Aliens? Mice?
  1984.  
  1985. +++++++++++++++++++++++++++
  1986.  
  1987. >From triple@nando.net (Joe Zobkiw)
  1988. Date: Sun, 24 Sep 1995 09:46:04 -0400
  1989. Organization: TripleSoft Inc.
  1990.  
  1991. In article <st955901-2409951759380001@ppp29.cowan.edu.au>,
  1992. st955901@pilot.stu.cowan.edu.au (Philip Cummins) wrote:
  1993.  
  1994. >Is there any way I can call an a-trap listed as 'do not call from
  1995. >interrupt' from an interrupt safely? And what exactly is the reason why we
  1996. >can't call them?
  1997.  
  1998. Probably not. The reason you can't call most patches from an interrupt
  1999. that are labeled as such is because they move memory or depend on the
  2000. state of the OS being a certain way that is not guaranteed to be that way
  2001. during interrupt time.
  2002.  
  2003. If it says you can't do it, you can't do it. Mind you, some may not be
  2004. labeled as such but may also be problematic to call from an interrupt as
  2005. well. For example, if someone patched a trap that is OK to call from
  2006. interrupt time but moves memory in their patch. This could cause problems.
  2007.  
  2008. Hope this helps.
  2009.  
  2010. Joe Zobkiw
  2011.  
  2012. - ----------------------------------------------------------------
  2013. TripleSoft Inc, Macintosh Software Development     CIS: 74631,1700
  2014. P.O. Box 30774, Raleigh, NC 27622-0774      AOL/eWorld: TripleSoft
  2015. voice/fax (919) 872-0916                Internet: Triple@nando.net
  2016. - ----------------------------------------------------------------
  2017.  Look for "A Fragment of Your Imagination" from Addison-Wesley...
  2018. PowerPC/Code Resources/Fragments/Components/Extensions/and more...
  2019.  
  2020. +++++++++++++++++++++++++++
  2021.  
  2022. >From Binky the Wonderwhorse <binky@mmcorp.com>
  2023. Date: 25 Sep 1995 10:37:23 GMT
  2024. Organization: MultiMedia Corporation
  2025.  
  2026. lo,
  2027.  
  2028. Some calls you can...the Async calls can be done so you can do PBControl
  2029. calls, PBFileBlurb calls and stuff so long as they're done asynchronously.
  2030.  
  2031. Seem to be a bit of a black art...and a bit stupid to have these
  2032. ridiculous restrictions imposed but I shan't start bitching...honest
  2033.  
  2034. Binky
  2035.  
  2036. +++++++++++++++++++++++++++
  2037.  
  2038. >From Richard Wesley <hawkfish@punchdeck.com>
  2039. Date: 25 Sep 1995 14:26:18 GMT
  2040. Organization: Punch Deck Consulting
  2041.  
  2042. Binky the Wonderwhorse <binky@mmcorp.com> wrote:
  2043. >lo,
  2044. >
  2045. >Some calls you can...the Async calls can be done so you can do PBControl
  2046. >calls, PBFileBlurb calls and stuff so long as they're done asynchronously.
  2047. >
  2048. >Seem to be a bit of a black art...and a bit stupid to have these
  2049. >ridiculous restrictions imposed but I shan't start bitching...honest
  2050.  
  2051. Its not really a black art - you are in a seperate thread and can only make
  2052. calls that are reentrant.  Shared resources must be managed by locks and
  2053. semaphores in such situations.
  2054.  
  2055. Large parts of the toolbox do not have such management facilities.  Most
  2056. significantly, the Memory Manager maintains a pool of memory for the main
  2057. thread and cannot be used by the interrupt level thread.  This means that
  2058. amything that uses the memory manager cannot be called.  Most other
  2059. resources you allocate from the system (e.g. GUI elements etc.) have similar
  2060. restrictions.  The notable exceptions are resources that can be accessed by
  2061. adding something to a queue and waiting for the result.  This means all 
  2062. drivers that allow asynchronous parameter blocks requests and some other 
  2063. managers that also allow such requests (e.g. SndDoCommand).  And anything
  2064. that manipulates only data from your interrupt level thread 
  2065. (e.g. BlockMoveData).
  2066.  
  2067. - rmgw
  2068.  
  2069. http://www.punchdeck.com/hawkfish/PunchDeck.html
  2070.  
  2071. - --------------------------------------------------------------------------
  2072. Richard Wesley  hawkfish@punchdeck.com | "What was that popping sound?"
  2073. Punch Deck Consulting pnchdeck@aol.com | "A paradigm shifting without a
  2074.      Macintosh Software Development    |  clutch."  - Dilbert (Scott Adams)
  2075. - --------------------------------------------------------------------------
  2076.  
  2077. +++++++++++++++++++++++++++
  2078.  
  2079. >From reed@medicine.wustl.edu (Thomas Reed)
  2080. Date: Tue, 26 Sep 1995 09:20:55 -0500
  2081. Organization: Washington University
  2082.  
  2083. In article <st955901-2409951759380001@ppp29.cowan.edu.au>,
  2084. st955901@pilot.stu.cowan.edu.au (Philip Cummins) wrote:
  2085.  
  2086. >Is there any way I can call an a-trap listed as 'do not call from
  2087. >interrupt' from an interrupt safely? And what exactly is the reason why we
  2088. >can't call them?
  2089.  
  2090. It looks like others have adequately answered why you can't call them, but
  2091. no one has mentioned a solution.  The best solution in such a case is to
  2092. just set a global flag to let you know that you need to do something. 
  2093. Then, somewhere, from some code that gets called frequently (and, more
  2094. importantly, that doesn't execute at interrupt time), check that flag and
  2095. do the appropriate thing.
  2096.  
  2097. Note that I've never done this before, I just know the principles.  So,
  2098. don't ask me for practical help, as I have none to give (except to say
  2099. that the book "Power Macintosh Programming Starter Kit" has an example of
  2100. exactly this case).
  2101.  
  2102. -Thomas
  2103.  
  2104. =====================================================
  2105. Thomas Reed                     Washington University
  2106. reed@visar.wustl.edu               Medical School
  2107. reed@medicine.wustl.edu            Saint Louis, MO
  2108. http://medinfo.wustl.edu/~reed
  2109. - ---------------------------------------------------
  2110. Clothes make the man.  Naked people have little or no
  2111. influence on society.  -- Mark Twain
  2112. =====================================================
  2113.  
  2114. Opinions posted are not the opinions of Wash. U.
  2115.  
  2116. +++++++++++++++++++++++++++
  2117.  
  2118. >From isis@netcom.com (Mike Cohen)
  2119. Date: Tue, 26 Sep 1995 18:11:09 GMT
  2120. Organization: ISIS International
  2121.  
  2122. st955901@pilot.stu.cowan.edu.au (Philip Cummins) writes:
  2123.  
  2124. >Hello,
  2125.  
  2126. >Is there any way I can call an a-trap listed as 'do not call from
  2127. >interrupt' from an interrupt safely? And what exactly is the reason why we
  2128. >can't call them?
  2129.  
  2130. No. The reason you can't call them is becuse those traps can move memory.
  2131. Remember that interrupts can occur asynchronously at unpredictable times
  2132. and the memory manager may be in some inconsistant state in the middle of
  2133. moving some block of memory. Since the memory manager is non-reentrant, if
  2134. you tried to do something that could move memory when it's already in the
  2135. process of moving memory, "unpredictable" results could happen.
  2136. -- 
  2137. Mike Cohen - isis@netcom.com
  2138. Home Page: ftp://ftp.netcom.com/pub/is/isis/home.html
  2139. Sound is the same for all the world - Youssou N'dour, "Eyes Open"
  2140.  
  2141.  
  2142. ---------------------------
  2143.  
  2144. End of C.S.M.P. Digest
  2145. **********************
  2146.